
var express = require('express');
var path = require('path')
var app = express();

var server = app.listen(8082, function () {
    var host = server.address().address;
    var port = server.address().port;
    console.log('Example app listening at http://%s:%s', host, port);
});

function socketVerify(info) {
    console.log(info.origin);
    console.log(info.req.t);
    console.log(info.secure);
    return true; //否则拒绝  
}
var WebSocketServer = require('ws').Server,
    wss = new WebSocketServer({
        port: 8181,
        verifyClient: socketVerify
    });

wss.on('connection', (ws) => {
    console.log('client connected');
    ws.on('message', (msg) => {
        console.log(msg)
    })
    ws.on('error', (error) => {
        console.log(error)
    })
    ws.on('close', (close) => {
        console.log(close)
    })
})